package cease.http;

import java.io.IOException;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;

/**
 * @author dhf
 */
public class HttpResponseHandler implements ResponseHandler<HttpRequestResult> {
    public HttpRequestResult handleResponse(HttpResponse response)
            throws IOException {
        HttpEntity entity = response.getEntity();
        byte[] content = EntityUtils.toByteArray(entity);
        String charset = EntityUtils.getContentCharSet(entity);
        int status = response.getStatusLine().getStatusCode();
        Header[] headers = response.getAllHeaders();
        return new HttpRequestResult(content, charset, status, headers);
    }
}
